package top.hcode.hoj.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import top.hcode.hoj.common.result.CommonResult;
import top.hcode.hoj.pojo.dto.BaseIdDTO;
import top.hcode.hoj.pojo.entity.CollUserStat;
import top.hcode.hoj.pojo.form.coll.AdmQueryCollUserStatForm;
import top.hcode.hoj.pojo.vo.coll.CollUserStatVO;
import top.hcode.hoj.service.UserAuthService;
import top.hcode.hoj.service.admin.AdminCollUserStatService;

/**
 * @author orangej
 * @since 2025-02-10
 */
@Slf4j
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class AdminCollUserStatController {

    private final AdminCollUserStatService collUserStatService;
    private final UserAuthService authService;

    @GetMapping("/admin/coll-user-stat/list")
    public CommonResult<IPage<CollUserStatVO>> getCollUserStatList(AdmQueryCollUserStatForm form) {
        return CommonResult.successResponse(collUserStatService.queryCollUserStatVO(form, authService.getSchoolIdList()));
    }

    @PostMapping("/admin/coll-user-stat/save")
    public CommonResult<CollUserStat> saveCollUserStat(@RequestBody CollUserStat collUserStat) {
        return CommonResult.successResponse(collUserStatService.saveCollUserStat(collUserStat));
    }

    @PostMapping("/admin/coll-user-stat/delete")
    public CommonResult<Void> deleteCollUserStat(@RequestBody BaseIdDTO dto) {
        collUserStatService.deleteCollUserStat(dto.getId());
        return CommonResult.successResponse();
    }

}
